import React, { useState } from "react";
import { reqRegister } from "../../request/api";
import Top from "../../components/Top/Top"
const Register = (props) => {
  const [user, setUser] = useState({ phone: "", password: "", nickname: "" });
   
  //注册
  const register = () => {
    reqRegister(user).then((res) => {
      if (res.data.code == 200) {
        props.history.push("/login");
      }
    });
  };
  const title = "手机注册"
  return (
    <div>
        <Top title={title}></Top>
      <h1>register</h1>
      <div>
        手机号：
        <input
          type="text"
          value={user.phone}
          onChange={(e) => setUser({ ...user, phone: e.target.value })}
        />
      </div>
      <div>
        昵称：
        <input
          type="text"
          value={user.nickname}
          onChange={(e) => setUser({ ...user, nickname: e.target.value })}
        />
      </div>
      <div>
        密码：
        <input
          type="text"
          value={user.password}
          onChange={(e) => setUser({ ...user, password: e.target.value })}
        />
      </div>
      <button onClick={() => register()}>注册</button>
    </div>
  );
};

export default Register;
